
$('.form-signin').addEventListener('submit', e => {
    e.preventDefault()
    const username = $('#inputUsername').value
const password = $('#inputPassword').value
const remember = $('#remember').checked
    console.log(username, password, remember);
    postAJAXWithPromise('http://localhost:8000/login.action', `username=${username}&password=${password}`)
        .then(resData => {
            const {
                code,
                data
            } = resData
            if (code === 200) {
                if (remember) {
                    setCookie('username', username, {expires: 5})
                    setCookie('password', password, {expires: 5})
                } else {
                    removeCookie('username')
                    removeCookie('password')
                }
                window.location.href = '/success.html'
            } else {
                $('.alert-warning').classList.remove('hidden')
            }
        })
        .catch(err => {
            console.log('err:', err);
        })
}, false)

window.onload = function () {
    const username = getCookie('username')
    const password = getCookie('password')
    $('#inputUsername').value = username
    $('#inputPassword').value = password
}

$('.close-btn').addEventListener('click',e=>{

    $('.alert-warning').classList.add('hidden')
},false)